#                                            元组
# 一、构建
'''
# 1、使用字面值
#使用字面值
sxt_tuple=(1)
print(type(sxt_tuple)) # <class 'int'> 只有一个元素，元素后面放一个"逗号才行"，不然会被认为是整形
sxt_tuple=(1,)
print(type(sxt_tuple)) # <class 'tuple'>
sxt_tuple=(1,2,3,'sxt','is','very','good',True)
print(sxt_tuple)  # (1, 2, 3, 'sxt', 'is', 'very', 'good', True)
'''


'''
# 2、使用构造函数
# 使用构造函数 
sxt_tuple=tuple([1,2,3,'sxt','is','very','good',True]) #将列表转为元组  
print(sxt_tuple)  # (1, 2, 3, 'sxt', 'is', 'very', 'good', True)
sxt_tuple=tuple(range(1,10,2)) #获取1~10之间的奇数
print(sxt_tuple)               #(1, 3, 5, 7, 9)
sxt_tuple=tuple(range(0,10,2)) #获取1~10之间的偶数
print(sxt_tuple)               #(0, 2, 4, 6, 8)
'''


'''
# 3、脚本操作符
# 脚本操作符
sxt_tuple=(1,2,3)+(4,5,6) #合并成一个容器
print(sxt_tuple)          #(1, 2, 3, 4, 5, 6)
sxt_tuple=(1,2,3)*5       #重复5次
print(sxt_tuple)          #(1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3)
'''


'''
# 二、获取
# 获取 
sxt_tuple=(1,2,3,'sxt','is','very','good',True)
print(sxt_tuple[0])   #获取元组第一个元素  正序    1
print(sxt_tuple[-8])   #获取元组第一个元素  倒序   1
print(len(sxt_tuple))   #获取整个元组的长度        8


#元组内容不可改变
#sxt_tuple[3]='shsxt'         #元组内容是不可更改的
#print(sxt_tuple)     #TypeError: 'tuple' object does not support item assignment
'''


# 三、分片
# 分片 左闭右开
sxt_tuple=(1,2,3,'sxt','is','very','good',True)
print(sxt_tuple[1:5]) #指定索引  结果为 (2, 3, 'sxt', 'is')
print(sxt_tuple[:])   #索引所有   (1, 2, 3, 'sxt', 'is', 'very', 'good', True)
print(sxt_tuple[0:])   #索引所有   (1, 2, 3, 'sxt', 'is', 'very', 'good', True)
print(sxt_tuple[0::2])  #偶数索引   (1, 3, 'is', 'good')
print(sxt_tuple[-1:-5:-1])  #指定索引倒序获取 (True, 'good', 'very', 'is')
print(sxt_tuple[-2:4])        #从倒序获取到正序 ->结果为空  ()

